<!DOCTYPE HTML>
<html>
	<head>
		<title>Editor</title>
		<meta charset="utf-8"/>
		<link href="/static/css/bootstrap.min.css" rel="stylesheet">
		<link href="/static/css/editormd.css" rel="stylesheet"/>
		<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0" />
		<script src="/static/js/jquery-3.6.0.min.js"></script>
		<script src="/static/js/main.js"></script>
		<script src="/static/js/bootstrap.min.js"></script>
		<script src="/static/js/editormd.js"></script>
		<script src="/static/js/main.js"></script>
		<script type="text/javascript" >
			var p  = sendPassage();
			var id = null;
			function tryloadPsg() {
				var h=window.location.hash;
				if(h){
					h=h.substr(1);
					loadPassage(h);
					$("#subm").text("保存");
				}else
					$("#subm").text("发布");
			}
			function loadPassage(d) {
				id=null;
				p.get(d,function (data) {
					try {
						$("#title").val(data.title);
						$("#content").val(data.content);
						$("#classify").val(data.classify);
						id=d;
					}catch (e) {
						
					}
				});
			}
			$(document).ready(function(){
				
				$(function() {
					window.mdEditor = editormd("test-editormd", {
						width   : "100%",
						height  : 320,
						path    : "/static/editormd/lib/",
						emoji: false,
     					taskList: true, 
						tocm: true,         // Using [TOCM]
   					tex: true,                   // 开启科学公式TeX语言支持，默认关闭
   					flowChart: true,             // 开启流程图支持，默认关闭
   					sequenceDiagram: true,       // 开启时序/序列图支持，默认关闭,
   					emoji: false,
   					toolbarIcons : function() {
   						return ["undo","redo","|","bold","del","italic","quote","uppercase","lowercase","|","h1","h2","h3","h4","h5","h6","|","list-ul","list-ol","hr","|","watch","preview","fullscreen","|","help","info"];
   					}
					});
				});
				
				$("#subm").click(function () {
					var title=$("#title").val();
					var cont=$("#content").val();
					var classify=$("#classify").val();
					if(id)
						p.edit(id,title,cont,classify);
					else
						p.send(title,cont,classify,function (res) {
							window.location.href="#"+res;
						});
				});
			
				tryloadPsg();
			});
			window.onhashchange=function () {
				tryloadPsg();
			}
		</script>
	</head>
	<body>
		
		<div id="test-editormd">
			<textarea id="content" class="form-control"></textarea>
		</div><br>
		
		<span style="float:right;">
			<button id="subm" ></button>
		</span>
		
	</body>
</html>
